﻿function Group() {
    var self = this;

    self.ShowUserWindow = function() {
        var ids = new Array();
        var list = $("#dataList").DataTable().rows({ selected: true }).data();
        $.each(list, function (index, item) {
            ids.push(item.id);
        });

        if (ids.length === 0) {
            window.app.message("请选中一项。");
            return;
        }
        if (ids.length > 1) {
            window.app.message("只能选中一项。");
            return;
        }

        parent.$('#ajaxModal').remove();

        var $remote = "/Platform/Group/LoadWindowForUser/?groupId=" + ids[0]
            , $modal = $('<div tips="用来做容器"></div>');
        parent.$('body').append($modal);

        $modal.load($remote, function () {
            var newmodal = $modal.children("div").modal();
            newmodal.modal('show');
        });
    }

    self.relation = function (event, groupId) {
        var $dataList = $(event.currentTarget).parents('.modal-dialog').find(".dataTable");
        var checkboes = $dataList.find(".checkColumn input:checked");

        var output = {
            groupId: groupId,
            userIds: []
        }

        checkboes.each(function (index, item) {
            output.userIds.push(item.value);
        });
        $.post($("#userWindowDataForm").data("url"), output, function (result) {
            if (data.errors.length > 0) {
                swal("出错啦！", data.errors, "error");

            } else {
                window.app.message("保存成功。");
            }
        });

    }
}